// miniprogram/pages/poetry/grade/detail/detail.js
const poetry_db = wx.cloud.database().collection('poetry')

Page({

  data: {
    poetry1: {
      title: "《咏鹅》",
      time: "[唐]",
      author: "骆宾王",
      content: [
        "鹅，鹅，鹅，曲项向天歌。",
        "白毛浮绿水，红掌拨清波。"
      ]
    },
    poetrysList: []
  },
  onLoad: function (options) {
    // console.log(options)
    var title = decodeURIComponent(options.title)
    var _this = this
    wx.setNavigationBarTitle({
      title: title
    })
    poetry_db.where({
      grade: title
    }).get({
      success: function (res) {
        var poetrys = res.data[0].poetrys
        console.log(res)
        _this.setData({
          poetrysList: poetrys
        })
      }
    })
  },
  //诗词列表点击监听
  onPoetryItemClick(e) {
    console.log(e)
    var poetryList = this.data.poetrysList
    var index = e.currentTarget.dataset.index
    var poetry = JSON.stringify(poetryList[index])
    console.log(poetry)
    wx.navigateTo({
      url: '../../detail/detail?poetry=' + encodeURIComponent(poetry)
    })
  }
})